package com.mc.lp.database.entity.helper;

import com.mc.lp.database.entity.AcademicRecordEntity;
import com.mc.lp.shared.vo.AcademicRecordVO;

public class AcademicRecordHelper implements IEntityHelper<AcademicRecordEntity, AcademicRecordVO> {

	public AcademicRecordVO getVO(AcademicRecordEntity entity) {
		
		AcademicRecordVO vo = new AcademicRecordVO();
		
		vo.setGradeId(entity.getGradeId());
		vo.setGradePointId(entity.getGradePointId());
		vo.setMarks(entity.getMarks());
		vo.setMaxMarks(entity.getMaxMarks());
		vo.setNewRow(false);
		vo.setSid(entity.getId());
		vo.setSubjectId(entity.getSubject().getId());
		vo.setTermId(entity.getTermId());
		vo.setYear(entity.getYear());
		vo.setRemarks(entity.getRemarks());
		vo.setAttributeWeightage(entity.getAttributeWeightage());
		
		return vo;
	}

	public AcademicRecordEntity getEntity(AcademicRecordVO vo) {
		AcademicRecordEntity entity = new AcademicRecordEntity();
		if(!vo.isNewRow())
		entity.setId(vo.getSid());
		setEntityInitialValues(entity,vo);
		return entity;
	}
	
	public void setEntity(AcademicRecordVO vo, AcademicRecordEntity entity) {
		setEntityInitialValues(entity,vo);
		
	}
	
	private void setEntityInitialValues(AcademicRecordEntity entity, AcademicRecordVO vo){
		entity.setMarks(vo.getMarks());
		entity.setMaxMarks(vo.getMaxMarks());
		entity.setGradePointId(vo.getGradePointId());
		entity.setYear(vo.getYear());
		entity.setTermId(vo.getTermId());
		entity.setGradeId(vo.getGradeId());
		entity.setRemarks(vo.getRemarks());
		entity.setAttributeWeightage(vo.getAttributeWeightage());
	}
	
}
